home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / source / Registers.c < prev    next >
Encoding:
Text File  |  1995-11-01  |  4.3 KB  |  181 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994,1995 Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware:
  5. you may copy, exchange, modify this code.
  6. You may include this code in any kind of application: freeware,
  7. shareware, or commercial, provided that full credits are given.
  8. You may not sell or distribute this code for profit.
  9. */
  10.  
  11. //#pragma load "MacDump"
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "Independents.h"
  15.  
  16. #include    "Disasm.h"
  17. #include    "DoEditDialog.h"
  18. #include    "Globals.h"
  19. #include    "Main.h"
  20. #include    "Registers.h"
  21. #include    "SimUtils.h"
  22.  
  23. #if defined(FabSystem7orlater)
  24.  
  25. //#pragma segment Main
  26.  
  27. /* CLRRECT: makes a Rect an empty Rect */
  28. #define    CLRRECT(r)    (*(long *)&r = 0, *(long *)((Ptr)&r + 2) = 0)
  29.  
  30. ControlHandle    Ctrl_Base;
  31. short    regLineHeight;
  32. short    regDistFromTop;
  33. short    regVertSepLine;
  34. short    oldChoice;
  35.  
  36. static void Do_A_Button(ControlHandle theControl);
  37.  
  38.  
  39. void Update_Registers(WindowPtr w)
  40. {
  41. Str255    sTemp;
  42. register Handle    tempH;
  43. register short i,j;
  44.  
  45. EraseRect(&w->portRect);
  46. HLock(tempH = Get1Resource('STR#', kREG_NAMES));
  47. for(i = 0, j = regDistFromTop; i <= kDISP_REGS - 1; i++, j += regLineHeight) {
  48.     MoveTo(REG_LEFT + kDIST_FROMLEFT, j);
  49.     DrawString((ConstStr255Param)GetPtrIndHString(tempH, i));
  50.     MoveTo(REG_LEFT + regVertSepLine + kDIST_FROMVERTSEP + 1, j);
  51.     FromNumToString(sTemp, gRegs[i], oldChoice);
  52.     DrawString(sTemp);
  53.     }
  54. HUnlock(tempH);
  55. /*  Draw the horizontal line  */
  56. MoveTo(REG_LEFT, kREG_HORZSEPLINE);
  57. LineTo(REG_RIGHT, kREG_HORZSEPLINE);
  58. /*  Draw the vertical line  */
  59. MoveTo(regVertSepLine, REG_TOP);
  60. LineTo(regVertSepLine, REG_BOTTOM - 1);
  61. UpdateControls(w, w->visRgn);
  62. }
  63.  
  64. void Do_Registers(WindowPtr w, EventRecord *theEvent)
  65. {
  66. Rect    tempRect, oldRect, shiftingRect;
  67. Point    myPt;
  68. ControlHandle    theControl;
  69. register short    code;
  70. register Boolean    inbigrect;
  71.  
  72. myPt = theEvent->where;
  73. GlobalToLocal(&myPt);
  74. if (FindControl(myPt, w, &theControl) != 0) {
  75.     if (TrackControl(theControl, myPt, (ControlActionUPP)-1L) == kControlLabelPart)
  76.         if ((code = GetControlValue(Ctrl_Base)) != oldChoice) {
  77.             oldChoice = code;
  78.             tempRect.top = REG_TOP;
  79.             tempRect.left = REG_LEFT + regVertSepLine + 1;
  80.             tempRect.bottom = REG_BOTTOM;
  81.             tempRect.right = REG_RIGHT;
  82.             InvalRect(&tempRect);
  83.             }
  84.     }
  85. else {
  86.     tempRect.top = REG_TOP;
  87.     tempRect.left = REG_LEFT;
  88.     tempRect.bottom = REG_BOTTOM;
  89.     tempRect.right = REG_RIGHT;
  90.     if (PtInRect(myPt, &tempRect)){
  91.         CLRRECT(oldRect);
  92.         do {
  93.             GetMouse(&myPt);
  94.             if (!PtInRect(myPt, &oldRect)) {
  95.                 if (inbigrect = PtInRect(myPt, &tempRect)) {
  96.                     shiftingRect.top = REG_TOP;
  97.                     shiftingRect.left = REG_LEFT;
  98.                     shiftingRect.bottom = REG_TOP + regLineHeight;
  99.                     shiftingRect.right = REG_RIGHT;
  100.                     for(code = kREG_PC;
  101.                         !(PtInRect(myPt, &shiftingRect)&&(code <= kREG_LOW8));
  102.                         code++, shiftingRect.top += regLineHeight,
  103.                         shiftingRect.bottom += regLineHeight)
  104.                             ;
  105.                     InvertRect(&oldRect);
  106.                     InvertRect(&shiftingRect);
  107.                     oldRect = shiftingRect;
  108.                     }
  109.                 else {
  110.                     InvertRect(&oldRect);
  111.                     CLRRECT(oldRect);
  112.                     }
  113.                 }
  114.             }
  115.         while( StillDown() );
  116.         if (inbigrect) {
  117.             InvertRect(&oldRect);
  118.             if(DoEditDialog(code, kREG_EXTNAMES, oldChoice)) {
  119.                 oldRect.left += regVertSepLine+1;
  120.                 InvalRect(&oldRect);
  121.                 if (code == kREG_PC)
  122.                     InvalDisasm();
  123.                 }
  124.             UnloadSeg(DoEditDialog);
  125.             }
  126.         }
  127.     }
  128. }
  129.  
  130. /* ChangedRegister: to tell us that a register has changed its value */
  131.  
  132. void ChangedRegister(short whichreg)
  133. {
  134. Rect    tempRect;
  135. GrafPtr    savePort;
  136.  
  137. GetPort(&savePort);
  138. SetPort(gWPtr_Registers);
  139. tempRect.top = REG_TOP + (regLineHeight * whichreg);
  140. tempRect.left = REG_LEFT + regVertSepLine+1;
  141. tempRect.bottom = tempRect.top + regLineHeight;
  142. tempRect.right = REG_RIGHT;
  143. InvalRect(&tempRect);
  144. if (whichreg == kREG_PC)
  145.     InvalDisasm();
  146. SetPort(savePort);
  147. }
  148.  
  149. /* ChangedAllRegisters: to tell us that _all_ registers have changed */
  150.  
  151. void ChangedAllRegisters(void)
  152. {
  153. Rect    tempRect;
  154. GrafPtr    savePort;
  155.  
  156. GetPort(&savePort);
  157. SetPortWindowPort(gWPtr_Registers);
  158. tempRect.top = REG_TOP;
  159. tempRect.left = REG_LEFT + regVertSepLine+1;
  160. tempRect.bottom = tempRect.top + (regLineHeight * kREG_ZERO);
  161. tempRect.right = REG_RIGHT;
  162. InvalRect(&tempRect);
  163. InvalDisasm();
  164. SetPort(savePort);
  165. }
  166.  
  167. /* procedure called when closing the Registers window */
  168.  
  169. void CloseRegisters(WindowPtr w)
  170. {
  171. DoCloseWindow(w, kMItem_Registers);
  172. }
  173.  
  174. void getDragRectRegs(WindowPtr w, RectPtr r)
  175. {
  176. *r = w->portRect;
  177. }
  178.  
  179. #endif
  180.  
  181.